﻿using Common.Communal;
using MediatR;
using Product.API.ISerivces.ProductProcess;
using Product.API.Write.Applications.Commands.ProductProcess;

namespace Product.API.Write.Applications.CommandHandlers.ProductProcess
{
    /// <summary>
    /// 产品工艺关联命令处理
    /// </summary>
    public class BatchProductProcessCommandHandler : IRequestHandler<BatchProductProcessCommand, ApiResult<int>>
    {
        /// <summary>
        /// 产品工艺关联服务 
        /// </summary>
        private readonly IProductProcessSerivce productProcessSerivces;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="productProcessSerivces">产品工艺关联服务</param>
        public BatchProductProcessCommandHandler(IProductProcessSerivce productProcessSerivces)
        {
            this.productProcessSerivces = productProcessSerivces;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回任务</returns>
        public async Task<ApiResult<int>> Handle(BatchProductProcessCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = EnumCode.Ok;
            result.Message = EnumCode.Ok.ToString();

            int data = await productProcessSerivces.BatchProductProcess(request.entity, request.ProcessRouteNumber);
            result.Data = data;

            return await Task.FromResult(result);
        }
    }
}
